#include <iostream>
#include <vector>
using namespace std;

//01 backpack
int main()
{
    int t;
    cin >> t;
    for (int tt = 0; tt < t; tt++)
    {
        int N, V;
        cin >> N >> V;
        vector<int> val(N, 0);
        vector<int> w(N, 0);
        vector<int> dp(V+1, 0);
        for (int i = 0; i < N; i++)
            cin >> val[i];
        for (int i = 0; i < N; i++)
            cin >> w[i];
        for (int i = 0; i < N; i++)
            for (int v = V; v >= w[i]; v--)
                dp[v] = max(dp[v], dp[v - w[i]] + val[i]);
        cout << dp[V]<<endl;
    }
    return 0;
}